<?php


namespace App\Utils\Notice;


use App\Model\NoticeEmployer;

class EmployerTaskNotAllow extends Notice
{

    public $messageTemplate = '很抱歉，您发布的任务审核失败，具体原因如下：“%message%”';

    //我发布的任务-审核失败
    public $routeName = '/pages/release/detail?id=%id%';

    public function toDatabase()
    {
        $data = $this->format($this->data);
        /** @var NoticeEmployer $model */
        $model = new NoticeEmployer();
        $model->fill($data)->save();
    }

    public function format($data)
    {

        $return  =  [
            'employer_id' => $this->receiverId,
            'content' => $this->messageTemplate,
            'type' => \App\Constants\Model\Notice::EMPLOYER_TASK_NOT_ALLOW,
            'extension' => [
                'path' => str_replace('%task_id%',$this->data['task_id'],$this->routeName)
            ]
        ];

        $searches = [];
        foreach ($data['replaces'] as $replace => $content) {
            $searches[] = '%' . $replace . '%';
        }
        $return['content'] = str_replace($searches, $data['replaces'], $this->messageTemplate);

        return $return;
    }
}